﻿using System;
using System.Linq;

namespace PBO.Data
{
    public enum PokemonNature : int
    {
        Hardy,
        Lonely,
        Brave,
        Adamant,
        Naughty,
        Bold,
        Docile,
        Relaxed,
        Impish,
        Lax,
        Timid,
        Hasty,
        Serious,
        Jolly,
        Naive,
        Modest,
        Mild,
        Quiet,
        Bashful,
        Rash,
        Calm,
        Gentle,
        Sassy,
        Careful,
        Quirky
    }

    public static class PokemonNatureHelper
    {
        private static readonly sbyte[,] REVISES = new sbyte[,]
        {
        { 10, 10, 10, 10, 10 },
        { 11, 9, 10, 10, 10 },
        { 11, 10, 9, 10, 10 },
        { 11, 10, 10, 9, 10 },
        { 11, 10, 10, 10, 9 },
        { 9, 11, 10, 10, 10 },
        { 10, 10, 10, 10, 10 },
        { 10, 11, 9, 10, 10 },
        { 10, 11, 10, 9, 10 },
        { 10, 11, 10, 10, 9 },
        { 9, 10, 11, 10, 10 },
        { 10, 9, 11, 10, 10 },
        { 10, 10, 10, 10, 10 },
        { 10, 10, 11, 9, 10 },
        { 10, 10, 11, 10, 9 },
        { 9, 10, 10, 11, 10 },
        { 10, 9, 10, 11, 10 },
        { 10, 10, 9, 11, 10 },
        { 10, 10, 10, 10, 10 },
        { 10, 10, 10, 11, 9 },
        { 9, 10, 10, 10, 11 },
        { 10, 9, 10, 10, 11 },
        { 10, 10, 9, 10, 11 },
        { 10, 10, 10, 9, 11 },
        { 10, 10, 10, 10, 10 }
        };

        public static int StatRevise(this PokemonNature nature, StatType stat)
        {
            if (stat == StatType.Hp) return 10;
            return REVISES[(int)nature, (int)stat - 1];
        }

        public static bool DislikeTaste(this PokemonNature nature, StatType stat)
        {
            return StatRevise(nature, stat) == 9;
        }

        public static int StatBoosted(this PokemonNature nature)
        {
            int n = (int)nature;
            for (int i = 0; i < REVISES.GetLength(1); i++)
            {
                if (REVISES[n, i] == 11)
                    return i + 1;
            }
            return 0;
        }

        public static int StatHindered(this PokemonNature nature)
        {
            int n = (int)nature;
            for (int i = 0; i < REVISES.GetLength(1); i++)
            {
                if (REVISES[n, i] == 9)
                    return i + 1;
            }
            return 0;
        }
    }
}